"""
case type   : 资源池化
case name   : ss_enable_verify_page参数验证
Create At   : 2023.10
Owner       : wx1224102
description :
    1、查看参数，校验原始默认值，当前参数值，参数类型，取值类型及范围
expect      :
    1、参数无法查询，只在debug版本使用
"""

import os
import unittest
from testcase.utils.CommonSH import CommonSH
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger


class SharedStorage(unittest.TestCase):

    def setUp(self):
        self.log = Logger()
        self.log.info(f'-----{os.path.basename(__file__)} start-----')
        self.constant = Constant()
        self.pri_sh = CommonSH('PrimaryDbUser')
        self.param = 'ss_enable_verify_page'

        self.log.info('------检查数据库状态是否正常------')
        status = self.pri_sh.exec_cm_ctl('query', '-Cv')
        self.assertIn("cluster_state   : Normal", status)

    def test_shared_storage(self):
        text = '-----step1:查看参数，校验默认值等; expect:参数无法查询-----'
        self.log.info(text)

        show_param = f'''show {self.param};'''
        self.log.info(show_param)
        param_value = self.pri_sh.execut_db_sql(show_param)
        self.log.info(param_value)
        self.assertIn(f'unrecognized configuration parameter "{self.param}"',
                      param_value, '查看参数成功')

        pri_config = f'''select * from pg_settings where name = '{self.param}';'''
        self.log.info(pri_config)
        pri_res = self.pri_sh.execut_db_sql(pri_config)
        self.log.info(pri_res)
        self.assertIn('(0 rows)', pri_res, '查看成功')

    def tearDown(self):
        text = '-----no need to clean-----'
        self.log.info(text)
        self.log.info(f'-----{os.path.basename(__file__)} end-----')
